package nz.ac.massey.jbuif.editor.components;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;

import nz.ac.massey.jbuif.editor.BeanEditor;

/**
 * Class BooleanEditorPanel
 * @author Daniel Haselden
 *
 */
public class BooleanEditorPanel extends BaseComponent implements ActionListener {

	private static final long serialVersionUID = 1L;
	private JCheckBox cb;
	
	
	/**
	 * BooleanEditorPanel
	 * @param p bean editor instance
	 * @param name string name
	 * @param displayName string name to be display
	 * @param pev an object
	 */
	public BooleanEditorPanel(BeanEditor p,String name,String displayName,Object pev) {
		super(p, name,displayName, pev);
		
		cb = new JCheckBox();
		
		if(pev!=null){
			cb.setSelected((Boolean)pev);
		} else {
			cb.setSelected(false);
		}
		
		cb.addActionListener(this);
		super.addPropertyComponent(cb);
		
	}

	
	/**
	 * actionPerformed
	 * @param e ActionEvent instance
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		ActionEvent e1 = new ActionEvent(e.getSource(), e.getID(), "checkBoxChanged");
		super.setPropertyValue(cb.isSelected());
		e1.setSource(this);
		getBeanEditor().actionPerformed(e1);
	}	
}
